<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户关系管理</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "客户关系管理",
        module: 'query',
        columns: [{
            name: "company.name",
            label: "客户公司",
            colspan: 1
        }, {
            name: "customerRole.ID",
            label: "角色",
            type: "dropdown",
            dropdownType: "ajax",
            url: "../base/dropdown-supCustomerRole",
            minLength: 0,
            colspan: 2
        }, {
            name: "CTIME",
            label: "添加日期从",
            type: "date"
        }, {
            name: "CTIME",
            label: "到",
            type: "date"
        }/*, {
         name : "CTIME",
         label : "到",
         type : "date"
         } */],
        buttons: {
            custom: [
                {
                    id: "addbtn",
                    value: "新增",
                    click: function () {
                        //$('#center', window.parent.document).attr("src","supCustomer-queryToManage");
                        window.location.href = "supCustomer-queryToManage";
                    }
                },
                {
                    id: "updateBtn",
                    value: "修改",
                    click: function () {
                        var id = $("#supCustomersDataGrid").jqGrid("getGridParam",
                                                                   "selrow");
                        if (id) {
                            var ret = $("#supCustomersDataGrid").jqGrid('getRowData', id);
                            //$('#center', window.parent.document).attr("src","supCustomer-manage?supCustomer.ID="+ret.ID);
                            window.location.href = "supCustomer-manage?supCustomer.ID=" + ret.ID;
                        } else {
                            jw.alert("请点击需要修改的数据!");
                        }
                    }
                },
                {
                    id: "delbtn",
                    value: "删除",
                    click: function () {
                        var selectedIds = $("#supCustomersDataGrid").jqGrid(
                                "getGridParam", "selarrrow");
                        if (selectedIds.length > 0) {
                            //if (confirm("确定要删除选择的项?")) {
                            jw.confirm("确定要删除选择的项?", function () {
                                           var data = "id=";
                                           for (i in selectedIds) {
                                               var ret = $("#supCustomersDataGrid").jqGrid('getRowData',
                                                                                           selectedIds[i]);
                                               data += ret.ID + ",";
                                           }
                                           data = data.substring(0, data.length - 1);
                                           $.ajax({
                                                      url: "supCustomer-del",
                                                      dataType: "json",
                                                      data: data,
                                                      success: function (data) {
                                                          jw.alert(data.msg);
                                                          $("#supCustomersDataGrid").jqGrid("setGridParam",
                                                                                            {
                                                                                                search: true
                                                                                                // 将jqGrid的search选项设为true
                                                                                            }).trigger(
                                                                  "reloadGrid", [{
                                                                      page: 1
                                                                  }]);
                                                      }
                                                  });
                                       },
                                       function () {
                                           return;
                                       });
                            //}
                        } else {
                            //alert("请点击需要删除的数据!");
                            jw.alert("请点击需要删除的数据!");
                        }

                    }
                }]
        },
        grid: {
            id: "supCustomersDataGrid",
            title: "查询结果",
            url: "supCustomer-findList",
            multiselect: true,
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "ID",
                name: "ID",
                hidden: true
            }, {
                index: "company.name",
                name: "company.name",
                label: "客户公司"
            }, {
                index: "customerRole.NAME",
                name: "customerRole.NAME",
                label: "角色名称"
            }, {
                index: "cTIME",
                name: "cTIME",
                label: "添加时间",
                formatter: 'date',
                //sorttype:'date',
                //editrules:{date:true},
                //search:false,
                //editable:false,
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
                //datefmt:'Y-m-d H:i:s'
            }/*, {
             index : "identifier",
             name : "identifier",
             label : "标识符"
             }, {
             index : "use_state",
             name : "use_state",
             label : "使用状态",
             formatter : function(cellvalue, options, rowObject) {
             if (cellvalue == "0") {
             return "启用";
             } else {
             return "禁用";
             }
             }
             }, {
             index : "updateUser",
             name : "updateUser",
             label : "修改人"
             }, {
             index : "updateDate",
             name : "updateDate",
             label : "修改时间"
             }  */],
            jsonReader: {
//                root: "supCustomers"
            }
        }
    };
    $(document).ready(function () {
        $("#supCustomersDataTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="supCustomersDataTable"></div>
</body>
</html>
